package com.gxa.meiye.sso.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.gxa.meiye.core.common.JsonResult;
import com.gxa.meiye.core.exception.BusinessException;
import com.gxa.meiye.core.pojo.vo.TherapistLoginInfo;
import com.gxa.meiye.sso.service.TherapistService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;
import java.util.Map;

@RestController
@RequestMapping("/mlstherapist")
public class TherapistLogin {
    @Autowired
    private TherapistService therapistService;
    @PostMapping("/login")
    @ApiOperation("登录方法")
    public JsonResult Login(@RequestParam("phone")
                                @NotEmpty(message = "手机号不为空")String phone,
                            @RequestParam("code")
                            @NotEmpty(message = "验证码不为空") String code) throws JsonProcessingException, BusinessException {
        String token = therapistService.login(phone, code);
        JsonResult jsonResult  = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setMsg("登录成功");
        jsonResult.set("token",token);

        return jsonResult;
    }
    @PostMapping("/checkToken")
    public Map queryUserByToken(String token) throws JsonProcessingException, BusinessException {
        TherapistLoginInfo therapistLoginInfo = therapistService.queryUserByToken(token);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setData(therapistLoginInfo);
        return  jsonResult.getMap();
    }



}
